package com.wxy.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.ModelAndView;

import com.wxy.domain.myException;

@ControllerAdvice
@ConditionalOnClass(DispatcherServlet.class)
public class myExceptionHandler {
	@ExceptionHandler(Exception.class)
	@ResponseBody
	public ModelAndView handler(Exception exception) {
		ModelAndView modelAndView=new ModelAndView();
		modelAndView.addObject("exception",exception.getMessage());
		modelAndView.setViewName("error");
		return modelAndView;
	}
	@ExceptionHandler(myException.class)
	@ResponseBody
	public ModelAndView handler2(myException exception) {
		ModelAndView modelAndView=new ModelAndView();
		modelAndView.addObject("exception",exception.getMessage());
		modelAndView.setViewName("error");
		return modelAndView;
	}
}
